<template><div><p>本文档最新版为 <a href="https://learnku.com/docs/laravel/10.x" target="_blank" rel="noopener noreferrer">10.x</a>，旧版本可能放弃维护，推荐阅读最新版！</p>
<h2 id="契约" tabindex="-1"><a class="header-anchor" href="#契约"><span>契约</span></a></h2>
<ul>
<li><a href="#introduction">介绍</a>
<ul>
<li><a href="#contracts-vs-facades">契约 Vs. Facades</a></li>
</ul>
</li>
<li><a href="#when-to-use-contracts">何时使用契约</a>
<ul>
<li><a href="#loose-coupling">低耦合</a></li>
<li><a href="#simplicity">简明</a></li>
</ul>
</li>
<li><a href="#how-to-use-contracts">如何使用契约</a></li>
<li><a href="#contract-reference">契约参考</a></li>
</ul>
<h2 id="介绍" tabindex="-1"><a class="header-anchor" href="#介绍"><span>介绍</span></a></h2>
<p>Laravel 的契约是一组接口，它们由框架提供并定义了核心服务。 例如，<code v-pre>Illuminate\Contracts\Queue\Queue</code> 契约 定义了队列任务需要的方法，而 <code v-pre>Illuminate\Contracts\Mail\Mailer</code> 契约定义了发送邮件需要的方法。</p>
<p>每一个契约都有框架提供的相应的实现。例如， Laravel 提供了对多种驱动的队列实现，和一个由<a href="https://swiftmailer.symfony.com/" target="_blank" rel="noopener noreferrer">SwiftMailer</a>驱动的邮件实现。</p>
<p>所有 Laravel 契约都在 <a href="https://github.com/illuminate/contracts" target="_blank" rel="noopener noreferrer">它们各自的 GitHub 仓库</a>。这为所有可用的契约以及扩展包开发者们可能用到的单个、解耦的包，提供了一个快速参考入口。</p>
<h3 id="契约-vs-facades" tabindex="-1"><a class="header-anchor" href="#契约-vs-facades"><span>契约 Vs. Facades</span></a></h3>
<p>Laravel 的 <a href="https://learnku.com/docs/laravel/6.x/facades" target="_blank" rel="noopener noreferrer">Facades</a> 和辅助函数提供了一种简便方式来使用 Laravel 服务而无需用到类型提示，也可在服务容器外部解析契约。多数情况下，每个 Facade 都有一个等效的契约。</p>
<p>和 Facades （不须要在你类中的构造函数去引用依赖）不同的是，契约允许你给自己的类定义明确的依赖。一些开发者更喜欢依赖被明确地定义出来，所以更倾向于使用契约，而其他开发者则享受于 Facades 带来的方便。</p>
<blockquote>
<p>Tip：在大多数应用中，无论你更喜欢 Facades 还是契约，都是没问题的。然而如果你在搭建扩展包，那你应该强烈考虑使用契约，因为他们更便于在包的上下文中做测试。</p>
</blockquote>
<h2 id="何时使用契约" tabindex="-1"><a class="header-anchor" href="#何时使用契约"><span>何时使用契约</span></a></h2>
<p>综上所述，使用契约还是 Facades 很大程度上取决于你个人或者团队的喜好。契约和 Facades 均可以用来构建健壮的、充分测试过的 Laravel 应用。只要你保持类的职责单一，你会发现使用契约和 Facades 的实际差别是非常小的。</p>
<p>然而，你也许仍有许多关于契约的问题。比方说，为啥都用接口 ？用接口不是更复杂吗？让我们在接下来的内容（「低耦合」与「简明性」）中，提炼出原因。</p>
<h3 id="低耦合" tabindex="-1"><a class="header-anchor" href="#低耦合"><span>低耦合</span></a></h3>
<p>首先，让我们来看一些缓存实现的高耦合代码。假设有下面代码：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Orders</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">Repository</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">   <span class="token doc-comment comment">/**</span>
<span class="line">     * 缓存实例</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">protected</span> <span class="token variable">$cache</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 创建一个新的仓库实例</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token punctuation">\</span>SomePackage<span class="token punctuation">\</span>Cache<span class="token punctuation">\</span>Memcached</span>  <span class="token parameter">$cache</span></span>
<span class="line">     * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">__construct</span><span class="token punctuation">(</span><span class="token class-name class-name-fully-qualified type-declaration"><span class="token punctuation">\</span>SomePackage<span class="token punctuation">\</span>Cache<span class="token punctuation">\</span>Memcached</span> <span class="token variable">$cache</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">cache</span> <span class="token operator">=</span> <span class="token variable">$cache</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 根据 ID 获取订单</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">int</span></span>  <span class="token parameter">$id</span></span>
<span class="line">     * <span class="token keyword">@return</span> <span class="token class-name">Order</span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">find</span><span class="token punctuation">(</span><span class="token variable">$id</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">cache</span><span class="token operator">-></span><span class="token function">has</span><span class="token punctuation">(</span><span class="token variable">$id</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token comment">//</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>在这个类中，代码与给定的缓存实现形成高度耦合。它的高度耦合是因为我们依赖了一个扩展包中具体的缓存类。如果该扩展包的 API 变了，那么我们的代码也将必须做出修改。</p>
<p>同理，如果我们想要将底层的缓存技术 （ Memcached ） 替换成另一种缓存技术 （ Redis ），我们得再次修改我们的代码库。我们的代码库不应该对谁提供的数据或者数据是怎么提供的有太多了解。</p>
<p><strong>我们可以通过依赖一个简单的与扩展包无关的接口来改进我们的代码，来替代之前的实现方式：</strong></p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Orders</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Contracts<span class="token punctuation">\</span>Cache<span class="token punctuation">\</span>Repository</span> <span class="token keyword">as</span> Cache<span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">Repository</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 缓存实例</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">protected</span> <span class="token variable">$cache</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 创建一个新的仓库实例.</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name">Cache</span>  <span class="token parameter">$cache</span></span>
<span class="line">     * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">__construct</span><span class="token punctuation">(</span><span class="token class-name type-declaration">Cache</span> <span class="token variable">$cache</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">cache</span> <span class="token operator">=</span> <span class="token variable">$cache</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>现在的代码不与任何特定的扩展包耦合了，甚至与 Laravel 都是无关的。由于契约扩展包不包含任何实现和依赖，你可以轻松地为给定的契约编写替代实现的代码，从而可以在不修改任何缓存代码的情况下替换缓存的实现。</p>
<h3 id="简明性" tabindex="-1"><a class="header-anchor" href="#简明性"><span>简明性</span></a></h3>
<p>当 Laravel 的所有服务都在简单的接口中简洁地定义时，很容易就可以确定给定服务提供的功能。<strong>契约是框架功能的简洁文档。</strong></p>
<p>此外，当您依赖简单的接口时，您的代码更易于理解和维护。您可以参考一个简单，干净的接口，而不是在大型复杂的类中跟踪哪些方法可用。</p>
<h2 id="如何使用契约" tabindex="-1"><a class="header-anchor" href="#如何使用契约"><span>如何使用契约</span></a></h2>
<p>那么，你如何实现契约呢？它实际上非常简单。<br>
Laravel中的许多类都通过<a href="https://learnku.com/docs/laravel/6.x/container" target="_blank" rel="noopener noreferrer">服务容器</a>解析, 包括控制器，事件监听器，中间件，队列任务，甚至路由闭包。因此，要获得契约的接口实现，你可以在正在解析的类的构造函数中「类型提示」接口。</p>
<p>例如，看看这个事件监听器:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Listeners</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>User</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Events<span class="token punctuation">\</span>OrderWasPlaced</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Contracts<span class="token punctuation">\</span>Redis<span class="token punctuation">\</span>Factory</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">CacheOrderInformation</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * Redis工厂实例</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">protected</span> <span class="token variable">$redis</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 创建新的事件处理程序实例</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name">Factory</span>  <span class="token parameter">$redis</span></span>
<span class="line">     * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">__construct</span><span class="token punctuation">(</span><span class="token class-name type-declaration">Factory</span> <span class="token variable">$redis</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">redis</span> <span class="token operator">=</span> <span class="token variable">$redis</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 处理事件.</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name">OrderWasPlaced</span>  <span class="token parameter">$event</span></span>
<span class="line">     * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">handle</span><span class="token punctuation">(</span><span class="token class-name type-declaration">OrderWasPlaced</span> <span class="token variable">$event</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token comment">//</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>解析事件侦听器后，服务容器将读取类的构造函数上的类型提示，并注入适当的值。要了解有关在服务容器中注册内容的更多信息，请查看其<a href="https://learnku.com/docs/laravel/6.x/container" target="_blank" rel="noopener noreferrer">文档</a>。</p>
<h2 id="契约参考" tabindex="-1"><a class="header-anchor" href="#契约参考"><span>契约参考</span></a></h2>
<p>此表提供了所有 Laravel 契约及其等效 facades 的快速参考:</p>
<table>
<thead>
<tr>
<th>契约</th>
<th>参考 Facade</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Auth/Access/Authorizable.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\Access\Authoriza...</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Auth/Access/Gate.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\Access\Gate</a></td>
<td><code v-pre>Gate</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Auth/Authenticatable.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\Authenticatable</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Auth/CanResetPassword.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\CanResetPassword</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Auth/Factory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\Factory</a></td>
<td><code v-pre>Auth</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Auth/Guard.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\Guard</a></td>
<td><code v-pre>Auth::guard()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Auth/PasswordBroker.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\PasswordBroker</a></td>
<td><code v-pre>Password::broker()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Auth/PasswordBrokerFactory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\PasswordBrokerFa...</a></td>
<td><code v-pre>Password</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Auth/StatefulGuard.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\StatefulGuard</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Auth/SupportsBasicAuth.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\SupportsBasicAut...</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Auth/UserProvider.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Auth\UserProvider</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Bus/Dispatcher.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Bus\Dispatcher</a></td>
<td><code v-pre>Bus</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Bus/QueueingDispatcher.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Bus\QueueingDispatche...</a></td>
<td><code v-pre>Bus::dispatchToQueue()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Broadcasting/Factory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Broadcasting\Factory</a></td>
<td><code v-pre>Broadcast</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Broadcasting/Broadcaster.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Broadcasting\Broadcas...</a></td>
<td><code v-pre>Broadcast::connection()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Broadcasting/ShouldBroadcast.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Broadcasting\ShouldBr...</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Broadcasting/ShouldBroadcastNow.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Broadcasting\ShouldBr...</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Cache/Factory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Cache\Factory</a></td>
<td><code v-pre>Cache</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Cache/Lock.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Cache\Lock</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Cache/LockProvider.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Cache\LockProvider</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Cache/Repository.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Cache\Repository</a></td>
<td><code v-pre>Cache::driver()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Cache/Store.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Cache\Store</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Config/Repository.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Config\Repository</a></td>
<td><code v-pre>Config</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Console/Application.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Console\Application</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Console/Kernel.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Console\Kernel</a></td>
<td><code v-pre>Artisan</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Container/Container.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Container\Container</a></td>
<td><code v-pre>App</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Cookie/Factory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Cookie\Factory</a></td>
<td><code v-pre>Cookie</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Cookie/QueueingFactory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Cookie\QueueingFactor...</a></td>
<td><code v-pre>Cookie::queue()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Database/ModelIdentifier.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Database\ModelIdentif...</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Debug/ExceptionHandler.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Debug\ExceptionHandle...</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Encryption/Encrypter.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Encryption\Encrypter</a></td>
<td><code v-pre>Crypt</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Events/Dispatcher.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Events\Dispatcher</a></td>
<td><code v-pre>Event</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Filesystem/Cloud.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Filesystem\Cloud</a></td>
<td><code v-pre>Storage::cloud()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Filesystem/Factory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Filesystem\Factory</a></td>
<td><code v-pre>Storage</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Filesystem/Filesystem.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Filesystem\Filesystem</a></td>
<td><code v-pre>Storage::disk()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Foundation/Application.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Foundation\Applicatio...</a></td>
<td><code v-pre>App</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Hashing/Hasher.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Hashing\Hasher</a></td>
<td><code v-pre>Hash</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Http/Kernel.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Http\Kernel</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Mail/MailQueue.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Mail\MailQueue</a></td>
<td><code v-pre>Mail::queue()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Mail/Mailable.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Mail\Mailable</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Mail/Mailer.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Mail\Mailer</a></td>
<td><code v-pre>Mail</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Notifications/Dispatcher.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Notifications\Dispatc...</a></td>
<td><code v-pre>Notification</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Notifications/Factory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Notifications\Factory</a></td>
<td><code v-pre>Notification</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Pagination/LengthAwarePaginator.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Pagination\LengthAwar...</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Pagination/Paginator.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Pagination\Paginator</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Pipeline/Hub.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Pipeline\Hub</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Pipeline/Pipeline.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Pipeline\Pipeline</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Queue/EntityResolver.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Queue\EntityResolver</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Queue/Factory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Queue\Factory</a></td>
<td><code v-pre>Queue</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Queue/Job.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Queue\Job</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Queue/Monitor.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Queue\Monitor</a></td>
<td><code v-pre>Queue</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Queue/Queue.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Queue\Queue</a></td>
<td><code v-pre>Queue::connection()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Queue/QueueableCollection.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Queue\QueueableCollec...</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Queue/QueueableEntity.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Queue\QueueableEntity</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Queue/ShouldQueue.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Queue\ShouldQueue</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Redis/Factory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Redis\Factory</a></td>
<td><code v-pre>Redis</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Routing/BindingRegistrar.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Routing\BindingRegist...</a></td>
<td><code v-pre>Route</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Routing/Registrar.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Routing\Registrar</a></td>
<td><code v-pre>Route</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Routing/ResponseFactory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Routing\ResponseFacto...</a></td>
<td><code v-pre>Response</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Routing/UrlGenerator.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Routing\UrlGenerator</a></td>
<td><code v-pre>URL</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Routing/UrlRoutable.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Routing\UrlRoutable</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Session/Session.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Session\Session</a></td>
<td><code v-pre>Session::driver()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Support/Arrayable.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Support\Arrayable</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Support/Htmlable.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Support\Htmlable</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Support/Jsonable.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Support\Jsonable</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Support/MessageBag.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Support\MessageBag</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Support/MessageProvider.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Support\MessageProvid...</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Support/Renderable.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Support\Renderable</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Support/Responsable.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Support\Responsable</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Translation/Loader.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Translation\Loader</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Translation/Translator.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Translation\Translato...</a></td>
<td><code v-pre>Lang</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Validation/Factory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Validation\Factory</a></td>
<td><code v-pre>Validator</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Validation/ImplicitRule.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Validation\ImplicitRu...</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Validation/Rule.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Validation\Rule</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Validation/ValidatesWhenResolved.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Validation\ValidatesW...</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/Validation/Validator.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\Validation\Validator</a></td>
<td><code v-pre>Validator::make()</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/View/Engine.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\View\Engine</a></td>
<td></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/View/Factory.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\View\Factory</a></td>
<td><code v-pre>View</code></td>
</tr>
<tr>
<td><a href="https://github.com/illuminate/contracts/blob/laravel/6.x/View/View.php" target="_blank" rel="noopener noreferrer">Illuminate\Contracts\View\View</a></td>
<td><code v-pre>View::make()</code></td>
</tr>
</tbody>
</table>
<p>本文章首发在 <a href="https://learnku.com/" target="_blank" rel="noopener noreferrer">LearnKu.com</a> 网站上。</p>
<blockquote>
<p>本译文仅用于学习和交流目的，转载请务必注明文章译者、出处、和本文链接<br>
我们的翻译工作遵照 <a href="https://learnku.com/docs/guide/cc4.0/6589" target="_blank" rel="noopener noreferrer">CC 协议</a>，如果我们的工作有侵犯到您的权益，请及时联系我们。</p>
</blockquote>
<hr>
<blockquote>
<p>原文地址：<a href="https://learnku.com/docs/laravel/6.x/contracts/5134" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/6.x/con...</a></p>
<p>译文地址：<a href="https://learnku.com/docs/laravel/6.x/contracts/5134" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/6.x/con...</a></p>
</blockquote>
</div></template>


